package com.bl.service.product;

import java.util.Random;

import com.bean.Product;
import com.bl.service.BeanFactory;
import com.bl.util.StringGenerator;
import com.dao.factory.DaoFactory.FactoryType;

/**
 * @author ${user}
 */
public class ProductFactory implements BeanFactory<Product>{

    private final FactoryType defaultFactoryType;

	public ProductFactory(FactoryType aDefaultFactoryType) {
		defaultFactoryType = aDefaultFactoryType;
	}


	@Override
    public Product createBean() {
        Product product = new Product();
        switch (defaultFactoryType) {
			case JDBC:
				product = new com.dao.jdbc.beans.Product();
				break;

			default:
				product = new Product();
				break;
		}
        return populateProduct(product);
    }


    @Override
    public Product updateBean(Product aProduct) {
        return populateProduct(aProduct);
    }

    private Product populateProduct(Product aProduct) {
        StringGenerator stringGenerator = new StringGenerator();
        Random random = new Random();
        int randomInt = random.nextInt(100);
        int price = randomInt;
        aProduct.setPrice(price);
        aProduct.setName(stringGenerator.generateRandomString(randomInt));
        aProduct.setDescription(stringGenerator.generateRandomString(randomInt));
        aProduct.setString1(stringGenerator.generateRandomString(randomInt));
        aProduct.setString2(stringGenerator.generateRandomString(randomInt));
        aProduct.setString3(stringGenerator.generateRandomString(randomInt));
        aProduct.setString4(stringGenerator.generateRandomString(randomInt));
        aProduct.setString5(stringGenerator.generateRandomString(randomInt));
        aProduct.setString6(stringGenerator.generateRandomString(randomInt));
        aProduct.setString7(stringGenerator.generateRandomString(randomInt));
        aProduct.setString8(stringGenerator.generateRandomString(randomInt));
        aProduct.setString9(stringGenerator.generateRandomString(randomInt));
        aProduct.setString10(stringGenerator.generateRandomString(randomInt));
        aProduct.setString11(stringGenerator.generateRandomString(randomInt));
        aProduct.setString12(stringGenerator.generateRandomString(randomInt));
        aProduct.setString13(stringGenerator.generateRandomString(randomInt));
        aProduct.setString14(stringGenerator.generateRandomString(randomInt));
        aProduct.setString15(stringGenerator.generateRandomString(randomInt));
        aProduct.setString16(stringGenerator.generateRandomString(randomInt));
        aProduct.setString17(stringGenerator.generateRandomString(randomInt));

        return aProduct;
    }
}
